package hu.myai.util;

import hu.myai.model.db.AxHistory;
import hu.myai.model.misc.KeyValue;

import java.util.Date;
import java.util.List;

public class Scenario {

	private DatabaseUtil dbUtil = new DatabaseUtil();

	private DownloadUtil downloadUtil = new DownloadUtil();

	public boolean gap(KeyValue[] retValue, String stock) {

		AxHistory lastSaved = dbUtil.getLastHistory(new Date(), stock);

		double gap = retValue[0].getValue() / retValue[1].getValue();
		double gapUpper = lastSaved.getClose() / retValue[1].getValue();
		double gapLower = retValue[0].getValue() / lastSaved.getClose();

		boolean goodForTrade = gap > 0.20 && gapLower * 5 < gapUpper;
		System.out.println("Trade: " + goodForTrade);
		return goodForTrade;
	}

	public boolean risingIndicator(List<Double> williamsR, List<Double> rateOfChange) {

		int histSize = williamsR.size() - 1;

		if (williamsR.get(histSize) < -50 && rateOfChange.get(histSize) < 0) {
			if (williamsR.get(histSize) >= williamsR.get(histSize - 1)
					&& rateOfChange.get(histSize) >= rateOfChange.get(histSize - 1)) {

			}
			return true;
		}

		return false;
	}

	public boolean tradeIsOngoing(List<AxHistory> stockList) {

		// check the volue
		AxHistory hist1 = stockList.get(stockList.size() - 1);
		AxHistory hist2 = stockList.get(stockList.size() - 2);

		if (hist1.getVolume() * hist1.getClose() < 10000 || hist2.getVolume() * hist2.getClose() < 10000
				|| Math.abs((hist1.getClose() / hist2.getClose()) - 1) < 0.04)
			return false;

		return true;
	}
}
